package com.nanhai.buddhist.college.module.study.controller.student.attendance;

import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.module.collegebase.api.student.vo.UpdatePasswordVO;
import com.nanhai.buddhist.college.module.collegebase.api.teacher.TeacherApi;
import com.nanhai.buddhist.college.module.collegebase.api.teacher.dto.TeacherRespDTO;
import com.nanhai.buddhist.college.module.study.controller.admin.attendanceleavereason.vo.AttendanceLeaveReasonRespVO;
import com.nanhai.buddhist.college.module.study.controller.admin.attendancemanagement.vo.AttendanceManagementListReqVO;
import com.nanhai.buddhist.college.module.study.controller.admin.attendancemanagement.vo.AttendanceManagementRespVO;
import com.nanhai.buddhist.college.module.study.controller.admin.classclockrecord.vo.ClockRecordRespVO;
import com.nanhai.buddhist.college.module.study.controller.admin.classclockrecord.vo.ClockRecordTodayReqVO;
import com.nanhai.buddhist.college.module.study.controller.student.attendance.vo.StudentClockRecordPageReqVO;
import com.nanhai.buddhist.college.module.study.controller.student.attendance.vo.StudentManagementPageReqVO;
import com.nanhai.buddhist.college.module.study.controller.teacher.vo.AttendanceManagementAddReq;
import com.nanhai.buddhist.college.module.study.convert.attendanceleavereason.AttendanceLeaveReasonConvert;
import com.nanhai.buddhist.college.module.study.convert.attendancemanagement.AttendanceManagementConvert;
import com.nanhai.buddhist.college.module.study.convert.classclockrecord.ClockRecordConvert;
import com.nanhai.buddhist.college.module.study.dal.dataobject.attendanceleavereason.AttendanceLeaveReasonDO;
import com.nanhai.buddhist.college.module.study.dal.dataobject.attendancemanagement.AttendanceManagementDO;
import com.nanhai.buddhist.college.module.study.dal.dataobject.classclockrecord.ClockRecordDO;
import com.nanhai.buddhist.college.module.study.enums.ClockRoleTypeEnum;
import com.nanhai.buddhist.college.module.study.service.attendanceleavereason.AttendanceLeaveReasonService;
import com.nanhai.buddhist.college.module.study.service.attendancemanagement.AttendanceManagementService;
import com.nanhai.buddhist.college.module.study.service.classclockrecord.ClockRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

/**
 * @author AKaipublic class AttendanceManagementAddReq {
 * @date 2022/8/25
 */

@Api(tags = "学生PC端- 学生考勤模块")
@RestController
@RequestMapping("/study/student/attendance")
@Validated
public class StudentAttendanceController {

    @Resource
    private AttendanceManagementService attendanceManagementService;

    @Resource
    private AttendanceLeaveReasonService attendanceLeaveReasonService;

    @Resource
    private ClockRecordService clockRecordService;

    @Resource
    private TeacherApi teacherApi;


    @PostMapping("/apply/leave")
    @ApiOperation("请假申请")
    public CommonResult<String> createAttendanceManagement(@Valid @RequestBody AttendanceManagementAddReq createReqVO) {
        createReqVO.setUserType(ClockRoleTypeEnum.STUDENT.getRole());
        return success(attendanceManagementService.createAttendanceManagement(createReqVO));
    }


    @GetMapping("/page")
    @ApiOperation("获取请假分页")
    public CommonResult<PageResult<AttendanceManagementRespVO>> getAttendanceManagementPage(@Valid StudentManagementPageReqVO pageVO) {
        pageVO.setUserType(ClockRoleTypeEnum.STUDENT.getRole());
        PageResult<AttendanceManagementDO> pageResult = attendanceManagementService.getAttendanceManagementPage(pageVO);
        return success(AttendanceManagementConvert.INSTANCE.convertPage(pageResult));
    }


    @GetMapping("/list")
    @ApiOperation("获取请假列表")
    public CommonResult<List<AttendanceManagementRespVO>> getAttendanceManagementListByQue(@Validated AttendanceManagementListReqVO reqVO) {
        reqVO.setUserType(ClockRoleTypeEnum.STUDENT.getRole()+"");
        List<AttendanceManagementDO> list = attendanceManagementService.getAttendanceManagementListByQue(reqVO);
        return success(AttendanceManagementConvert.INSTANCE.convertList(list));
    }


    @GetMapping("/studentClockPage")
    @ApiOperation("获得打卡记录分页")
    public CommonResult<PageResult<ClockRecordRespVO>> getStudentClockRecordPage(@Validated StudentClockRecordPageReqVO pageVO) {
        pageVO.setRole(ClockRoleTypeEnum.STUDENT.getRole());
        PageResult<ClockRecordDO> pageResult = clockRecordService.getStudentClockRecordPage(pageVO);
        return success(ClockRecordConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/getTodayClock")
    @ApiOperation("获取今日课程打卡详情")
    public CommonResult<List<ClockRecordRespVO>> getTodayClock(@Validated ClockRecordTodayReqVO recordTodayReqVO) {
        List<ClockRecordDO> todayClock = clockRecordService.getTodayClock(recordTodayReqVO);
        return success(ClockRecordConvert.INSTANCE.convertList(todayClock));
    }

    @GetMapping("/getLeaveReason")
    @ApiOperation("获取请假事由表")
    public CommonResult<List<AttendanceLeaveReasonRespVO>> getLeaveReasonAllList() {
        List<AttendanceLeaveReasonDO> list = attendanceLeaveReasonService.getAttendanceLeaveReasonAllList();
        return success(AttendanceLeaveReasonConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/studentSubmitList")
    @ApiOperation("学生提交人列表")
    public CommonResult<List<TeacherRespDTO>> getStudentSubmitListByClassId(@RequestParam("id") String id) {
        return teacherApi.getTeacherListByStudentId(id);
    }

    @GetMapping("/get")
    @ApiOperation("获得考勤管理")
    public CommonResult<AttendanceManagementRespVO> getAttendanceManagement(@RequestParam("id") String id) {
        AttendanceManagementDO attendanceManagement = attendanceManagementService.getAttendanceManagement(id);
        return success(AttendanceManagementConvert.INSTANCE.convert(attendanceManagement));
    }

    @PostMapping("/updatedPassWord")
    @ApiOperation("修改密码")
    CommonResult<Boolean> updatedStudentPassword(@RequestBody UpdatePasswordVO req) {
        teacherApi.updatedStudentPassword(req);
        return CommonResult.success(true);
    }


}
